package com.eds.mall.product.web;

import com.eds.mall.product.entity.CategoryEntity;
import com.eds.mall.product.service.CategoryService;
import com.eds.mall.product.vo.Catalog2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author zz_code
 * @data 2024/5/11 22:30
 */
@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","/index","/index.html"})
    public String index(Model model) {
        long start = System.currentTimeMillis();
        List<CategoryEntity> categoryEntities = categoryService.listLevel1Category();
        model.addAttribute("categorys", categoryEntities);
        System.out.println("获取一级目录结果并返回------------------");
        System.out.println("查询返回时间：" + (System.currentTimeMillis()-start)+"-->" + Thread.currentThread().getName());
        return "index";
    }

    @GetMapping("index/catalog.json")
    @ResponseBody
    public Map<String, List<Catalog2VO>> listOtherLevelCategory() {
        Map<String, List<Catalog2VO>> map = categoryService.getCatelog2JSON();
        return map;
    }
}
